<?php
/**
 * @title 155. 最小栈
 * @author start2004
 */

// ini_set("memory_limit", "128M");

// class Solution {
//
//     function find() {
//
//     }
// }


class MinStack {
    /**
     */
    function __construct() {
        /**
         * @since 2023-12-22 维持2个栈，一个栈正常存储数据，另一个栈存储最小值
         */
        $this->stack = new SplStack();
        $this->minStack = new SplStack();
    }

    /**
     * @param Integer $val
     * @return NULL
     */
    function push($val) {
        /**
         * @since 2023-12-22 将数据压入正常栈
         */
        $this->stack->push($val);

        /**
         * @since 2023-12-22 如果最小栈为空，或者当前值小于等于最小栈顶元素，则将当前值压入最小栈
         */
        if($this->minStack->isEmpty() OR $val <= $this->minStack->top()){
            $this->minStack->push($val);
        } else {
            /**
             * @since 2023-12-22 否则将最小栈顶元素再次压入最小栈
             */
            $this->minStack->push($this->minStack->top());
        }
    }

    /**
     * @return NULL
     */
    function pop() {
        /**
         * @since 2023-12-22 正常栈和最小栈都弹出栈顶元素
         */
        $this->stack->pop();
        $this->minStack->pop();
    }

    /**
     * @return Integer
     */
    function top() {
        /**
         * @since 2023-12-22 返回正常栈栈顶元素
         */
        return $this->stack->top();
    }

    /**
     * @return Integer
     */
    function getMin() {
        /**
         * @since 2023-12-22 返回最小栈栈顶元素
         */
        return $this->minStack->top();
    }
}

/**
 * Your MinStack object will be instantiated and called as such:
 * $obj = MinStack();
 * $obj->push($val);
 * $obj->pop();
 * $ret_3 = $obj->top();
 * $ret_4 = $obj->getMin();
 */




/**
 * @url http://127.0.0.1/leetcode/202312/2023.12.22_8.php
 */
$datas = [

];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    if(count($data) <= 20){
        var_dump($data);
    } else {
        var_dump(count($data));
    }

    $obj = new Solution();
    $result = $obj->(...$data);
    // $result = $obj->($xhprof->tree($data));
    // $result = $obj->($xhprof->listNode($data));
    // $result = $obj->find(...$data);
    var_dump($result);
    // if(count($result)<=20){
    //     var_dump($result);
    // } else {
    //     var_dump(count($result));
    // }
    echo str_repeat(PHP_EOL, 3);
    echo str_repeat("<br>", 3);
}

// foreach ($datas as $data){
//     $obj = new $data[0][0](...$data[1][0]);
//
//     for ($i=1; $i<count($data[0]); $i++){
//         $func = $data[0][$i];
//         $param = $data[1][$i];
//         $result = $obj->$func(...$param);
//
//         echo $data[0][$i] ."(\"". implode(",", $data[1][$i]) ."\") ";
//             if($result === true){
//                 echo "True";
//             } elseif($result === false) {
//                 echo "False";
//             } elseif($result === null) {
//                 echo "Null";
//             } elseif(is_array($result)) {
//                 var_dump($result);
//             } else {
//                 echo $result;
//             }
//         echo PHP_EOL;
//     }
//
//     echo str_repeat(PHP_EOL, 3);
// }
$xhprof->end();
